<template>
  <!-- 大日历 -->
  <view v-show="hideModal" class="container">
    <view class="mask" @touchmove.stop.prevent @click.stop="close()" />
    <view
      :class="devtools==='ios'?'content-ios bottom-pos':'content bottom-pos'"
      :animation="animationData"
      @touchmove.stop.prevent
    >
      <view class="select-date">
        <!-- 头部，关闭部分 -->
        <view class="select-date-head">
          <text>选择日期</text>
          <image
            src="@/static/image/default/contacts/close.png"
            @click.stop="close()"
          />
        </view>
        <!-- 引入日历 -->
        <uniCalendar
          :my-data="dateList"
          :insert="true"
          :lunar="true"
          :show-month="false"
          :date="datetime"
          :price="price"
          @change="change"
        />
      </view>
    </view>
  </view>
</template>
<script>
import uniCalendar from '@com/uni-calendar/uni-calendar'
import { get } from '@utils/storage'
import { extractionAnimation } from '@utils/myApproach'
export default {
  components: { uniCalendar },
  props: {
    show: {
      type: Boolean,
      required: false
    },
    datetime: {
      type: String,
      default: null
    },
    price: {
      type: String,
      default: null
    },
    dateList: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      hideModal: false, // 模态框的状态  true-隐藏  false-显示
      animationData: {}, //
      val: 0
    }
  },
  computed: {
    devtools() {
      return get('devtools')
    }
  },
  watch: {
    show(val) {
      if (val) {
        this.showModal()
      }
    }
  },
  methods: {
    // 显示遮罩层
    showModal: function() {
      var that = this
      that.hideModal = true
      this.animation = extractionAnimation()
      setTimeout(function() {
        that.fadeIn() // 调用显示动画
      }, 50)
    },
    // 隐藏遮罩层
    close: function() {
      var that = this
      this.animation = extractionAnimation()
      that.fadeDown() // 调用隐藏动画
      setTimeout(function() {
        that.hideModal = false
        that.$emit('close', !that.show)
      }, 50) // 先执行下滑动画，再隐藏模块
    },
    // 动画集
    fadeIn: function() {
      this.animation.translateY(0).step()
      this.animationData = this.animation.export() // 动画实例的export方法导出动画数据传递给组件的animation属性
    },
    fadeDown: function() {
      if (this.devtools === 'ios') {
        this.animation.translateY(930).step() // 移动的距离
      } else {
        this.animation.translateY(996).step() // 移动的距离
      }
      this.animationData = this.animation.export()
    },
    change(e) {
      this.$emit('changeDate', e.fulldate)
    }
  }
}
</script>
<style >
.mask {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  position: fixed;
  top: 0;
  left: 0;
}
.content {
  width: 100%;
  height: 930rpx;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #ffffff;
  z-index: 1000;
  border-radius: 20rpx 20rpx 0 0;
  overflow: hidden;
}
.content-ios{
  width: 100%;
  height: 996rpx;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #ffffff;
  z-index: 1000;
  border-radius: 20rpx 20rpx 0 0;
  overflow: hidden;
}
/*动画前初始位置*/
.bottom-pos {
  -webkit-transform: translateY(100%);
  transform: translateY(100%);
}
</style>
<style lang="scss" scoped>
.select-date {
  width: 100%;
  height: 100%;
}
.select-date-head {
  display: flex;
  justify-content: space-between;
  margin-top: 40rpx;
  margin-bottom: 30rpx;
}
.select-date-head > text {
  font-size: 32rpx;
  color: #000000;
  font-weight: 400;
  margin-left: 30rpx;
}
.select-date-head > image {
  width: 32rpx;
  height: 32rpx;
  margin-right: 30rpx;
  margin-top: 6rpx;
}
</style>
